using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Reflection;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Storage;

using MegaEngine.Source.Tiles;
using MegaEngine.Source.Sprites;

namespace MegaEngine.Source.GameData
{
    /*
     * This class needs to be replaced with one that reads from XML in a much more custom manner!
     */
    class LevelLoader
    {
        private static ArrayList environment = new ArrayList();
        private static ArrayList mobs = new ArrayList();

        public static ArrayList loadEnvironmentData(String fileName)
        {
            ArrayList result = new ArrayList();
            StreamReader sr = File.OpenText(fileName + ".environment");
            String line = sr.ReadLine();
            while (line != null)
            {
                line = line.Trim();
                if (line.StartsWith("#") == false)
                {
                    result.Add(line);
                }
                line = sr.ReadLine();
            }
            return result;
        }
        public static void writeEnvironmentData(String fileName, ArrayList sprites){
            StreamWriter sw = new StreamWriter(fileName + ".environment", false);
            foreach(Sprite s in sprites){
                Type t = s.GetType();
                String toWrite = t.ToString() + " " + s.textureID + " " + s.levelOrigin.X + " " + s.levelOrigin.Y + "\r\n";
                sw.Write(toWrite);
            }
            sw.Close();
        }
    }
}
